<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel=StyleSheet HREF="../stylesheet/stylesheet.css" TYPE="text/css" MEDIA=screen>
<title>Shop Management System</title>
<?php include('menu.php'); ?>
<?php
	if(isset($_SESSION['user_group_id'])){
		if($_SESSION['user_group_id']!=1) {
		echo "<script>window.location = '../index.php';</script>";
   		exit();
		}
	}
?>
</head>
<body onload="document.formadd.category.focus();">
<?php

if($_GET["action"]==add) {

	if(!$_POST["category"]=="" && $_POST['category_head'] != "") {
		include("../connect/connect.php");

		$checkcode = "SELECT category_head FROM category WHERE category_head = '".$_POST["category_head"]."'";
		$result = mysql_query($checkcode) or die ("'".checkcode."'");
		$row = mysql_num_rows($result);

		if($row>=1){
			$save="รหัสนำหน้าหมวดสินค้า ".$_POST["category_head"]." นี้มีอยู่แล้วกรุณาใช้รหัสอื่น";
		} else {

			$category_head = strtoupper($_POST['category_head']);
			$Query = "INSERT INTO category (category_name,category_head) VALUES ('".$_POST["category"]."','$category_head') ";
			$objQuery = mysql_query($Query);

			if($objQuery) {
				$save="บันทึกข้อมูลเรียบร้อยแล้ว";
			} else {
				echo "Error Save [".$Query."]";
			}
		}
	} else {
		$save="กรุณากรอกข้อมูลให้ครบ";
	}
}
?>
<form action="?action=add" name="formadd" method="post" id="formadd">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading">
      <h1>เพิ่มหมวดสินค้า</h1>
    <div class="buttons"><a onclick="formadd.submit();" class="button"><span>บันทึก</span></a><a onclick="location = 'product_manage_category.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
    <table class="form">
      <tr>
        <td>ชื่อหมวดสินค้า : </td>
        <td><input type="text" name="category" id="category" onkeyup="IsScharacter(this.value,this)" /></td>
      </tr>
      <tr>
        <td>รหัสนำหน้าหมวดสินค้า : </td>
        <td><input name="category_head" type="text" id="category_head" onkeyup="noThaichar(this.value,this)" value="" /></td>
      </tr>
    </table>
	<?php echo "<br><font color=\"red\"><center>$save</center></font>"; ?>
  </div>
</div>
</form>
</body>
</html>
